package com.lazi.june.web.interceptor;

import com.google.common.collect.Lists;
import com.lazi.june.common.base.RequestConst;
import com.lazi.june.common.util.JsonUtil;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * desc:
 *
 * @author huliqian
 * @since 2025/8/22
 */
@Slf4j
@Component
@ConditionalOnMissingBean(HeaderCheckStrategy.class)
@RequiredArgsConstructor
public class DefaultHeaderCheckStrategy implements HeaderCheckStrategy {

    private final HttpServletRequest request;

    @Override
    public void check() {
        Lists.newArrayList(
                RequestConst.APP_ID,
                RequestConst.DEVICE_TYPE,
                RequestConst.PLATFORM,
                RequestConst.TENANT_ID,
                RequestConst.VERSION
        ).forEach(headerName ->
                Optional.ofNullable(request.getHeader(headerName))
                        .ifPresent(headerValue -> log.info("headerName:{},headerValue:{}", headerName, headerValue)));

        Optional.ofNullable(request.getHeader(RequestConst.USER_INFO))
                .ifPresent(userInfo -> log.info("userInfo:{}", JsonUtil.toJsonStr(userInfo)));
    }
}
